import Vue from 'vue'
import Router from 'vue-router'
// 二级路由
import Edit from './views/pages/components/Edit'
import Details from './views/pages/components/Details'
// 一级路由
const Home = () => import('./views/pages/Home')
const About = () => import('./views/pages/About')
const Message = () => import('./views/pages/vuex/Message')
const Add = () => import('./views/pages/Add')
Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: '/home' // 路由重定向
    },
    {
      path: '/home',
      name: 'home',
      component: Home,
      meta: {
        showFooter: true // 如果当面页面没有底部导航栏显示则为false
      }
    },
    {
      path: '/about',
      name: 'about',
      component: About,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/message',
      name: 'message',
      component: Message,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/add',
      name: 'add',
      component: Add,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/details/:id',
      name: 'details',
      component: Details,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/edit/:id',
      name: 'edit',
      component: Edit,
      meta: {
        showFooter: false
      }
    }
  ],
  // 滚动行为
  scrollBehavior (to, from, savedPosition) { // scrollBehavior 方法接收 to 和 from 路由对象。第三个参数 savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用。
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})
